package app

import (
	"github.com/robfig/revel"
	"github.com/robfig/revel/modules/jobs/app/jobs"
	"kaibb/app/utils"
	"labix.org/v2/mgo/bson"
	"reflect"
)

func init() {

	//注册自定义函数

	revel.TemplateFuncs["id2String"] = utils.Id2String
	revel.TemplateFuncs["HTML"] = utils.Html
	// register the custom bson.ObjectId binder
	objId := bson.NewObjectId()
	revel.TypeBinders[reflect.TypeOf(objId)] = utils.ObjectIdBinder
	// Filters is the default set of global filters.
	revel.Filters = []revel.Filter{
		revel.PanicFilter,             // Recover from panics and display an error page instead.
		revel.RouterFilter,            // Use the routing table to select the right Action
		revel.FilterConfiguringFilter, // A hook for adding or removing per-Action filters.
		revel.ParamsFilter,            // Parse parameters into Controller.Params.
		revel.SessionFilter,           // Restore and write the session cookie.
		revel.FlashFilter,             // Restore and write the flash cookie.
		revel.ValidationFilter,        // Restore kept validation errors and save new ones from cookie.
		revel.I18nFilter,              // Resolve the requested language
		revel.InterceptorFilter,       // Run interceptors around the action.
		revel.CompressFilter,          // Compress the result.
		revel.ActionInvoker,           // Invoke the action.
	}

	revel.OnAppStart(func() { jobs.Schedule("cron.testJob", utils.TestJob{}) })
}
